﻿var ukCrossChargeType = newValue;
var expenseType = ref.ExpenseType.getValue();
var viewStatus = this.lookupController().analysis().status;

switch (ukCrossChargeType) {
    case 'JLRCUK':
        ref.UKGLCode.show();
        ref.UKCostCenter.show();
        ref.ukCrossChargeAttachments.show();
        ref.CompanyAllocation.hide();
        ref.BrandAllocationJLRC.show();
        ref.ProjectXAllocation.hide();

        if (self.containsFocus) {
            ref.UKGLCode.setAllowBlank(false);
            ref.UKCostCenter.setAllowBlank(false);
        }
        break;
    case 'UKJLRC':
        ref.UKGLCode.hide();
        ref.UKCostCenter.hide();
        ref.ukCrossChargeAttachments.show();
        ref.CompanyAllocation.show();
        ref.BrandAllocationJLRC.show();
        ref.ProjectXAllocation.hide();

        if (self.containsFocus) {
            ref.UKGLCode.setValue('');
            ref.UKCostCenter.setValue('');
            ref.file7.store.removeAll();
        }
        var grid3 = ref.datagrid3,
            editor3 = grid3.getColumns()[2].getEditor;
        if (editor3) {
            editor3 = grid3.getColumns()[2].getEditor();
            editor3.getStore().loadData([
                { name: "JLRC", code: "JLRC" },
                { name: "CJLR", code: "CJLR" }
            ]);
        }
        break;
    case 'PX':
        ref.ukCrossChargeAttachments.hide();
        ref.CompanyAllocation.hide();
        ref.BrandAllocationJLRC.hide();
        ref.ProjectXAllocation.hide();
        ref.UKGLCode.hide();
        ref.UKCostCenter.hide();

        if (ukCrossChargeType == 'PX') {
            ref.ProjectXAllocation.show();

            if (expenseType == '5') {
                ref.UKGLCode.show();
                ref.UKCostCenter.show();
            }
        } 

        if (self.containsFocus) {

            if (expenseType == '5' && ukCrossChargeType == 'PX') {
                ref.UKGLCode.setAllowBlank(false);
                ref.UKCostCenter.setAllowBlank(false);
            }
        }
        break;
    case 'No':
        ref.UKGLCode.hide();
        ref.UKCostCenter.hide();
        ref.ukCrossChargeAttachments.hide();
        ref.CompanyAllocation.show();
        ref.BrandAllocationJLRC.show();
        ref.ProjectXAllocation.hide();

        var grid3 = ref.datagrid3,
            editor3 = grid3.getColumns()[2].getEditor;
        if (editor3) {
            editor3 = grid3.getColumns()[2].getEditor();
            editor3.getStore().loadData([
                { name: "JLRC", code: "JLRC" },
                { name: "CJLR", code: "CJLR" },
                { name: "LRE", code: "LRE" }
            ]);
        }
        break;
    default:
}

ref.SharingPrinciple.hide();
ref.companySharingRatioTips.hide();

if (expenseType != '4') {
    ref.SharingPrinciple.setHidden(ukCrossChargeType != 'No');
    ref.companySharingRatioTips.setHidden(ukCrossChargeType != 'No');

    if (ukCrossChargeType == 'No') {
        //隐藏的控件名称,显示的控件名称的集合,true: 隐藏 false: 显示
        var showOrHideFieldObj = {
            SharingPrinciple: false,
            companySharingRatioTips: false,
            costCategory: false
        };
        switch (expenseType) {
            case '1':
            case '4':
                showOrHideFieldObj.SharingPrinciple = true;
                showOrHideFieldObj.companySharingRatioTips = true;
                showOrHideFieldObj.costCategory = true;
                break;
            case '5':
                showOrHideFieldObj.SharingPrinciple = true;
                showOrHideFieldObj.companySharingRatioTips = true;
                if (self.containsFocus) {
                    ref.costCategory.setValue('Asset');
                }
                break;
        }

        for (var ctrName in showOrHideFieldObj) {
            ref[ctrName].setHidden(showOrHideFieldObj[ctrName]);
        }
    }
}
var company = ref.companyC.getValue();

if (company == 'LRE') {
    //品牌分摊字表最终判断.如果公司是LRE.就隐藏.
    ref.BrandAllocationJLRC.hide();
    ref.SharingPrinciple.hide();
    ref.companySharingRatioTips.hide();
    ref.costCategory.hide();
    ref.costCategory.setValue('')
}

if (self.containsFocus) {
    ref.datagrid2.store.removeAll();
    ref.datagrid7.store.removeAll();

    ref.datagrid3.store.removeAll();
    ref.datagrid4.store.removeAll();
    ref.datagrid5.store.removeAll();
    ref.datagrid6.store.removeAll();

    ref.datagrid3.getColumns()[0].getEditor().store.data.removeAll();
    ref.datagrid4.getColumns()[0].getEditor().store.data.removeAll();
    ref.datagrid5.getColumns()[0].getEditor().store.data.removeAll();
    ref.datagrid6.getColumns()[0].getEditor().store.data.removeAll();
}